
<template>
<div class="goods-list">
    <router-link class="goods-item" v-for="item in goodsList" :key="item.id" to="/home/goodInfo" tag="div">
        <img :src="item.img_url" alt="">
        <h1 class="title">{{ item.title }}</h1>
        <div class="info">
            <p class="price">
                <span class="now">￥{{ item.sell_price }}</span>
                <span class="old">￥{{ item.market_price }}</span>
            </p>
            <p class="sell">
                <span>热卖中</span>
                <span>{{ item.stock_quantity }}</span>
            </p>
        </div>
    </router-link>
    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
</div>
</template>    
<script>
export default{
    data(){
        return {
            pageIndex:0,
            goodsList:[]
        }
    },
    created(){
        this.getGoodsList();
    },
    methods:{
        // 获取商品列表
        getGoodsList(){
            this.$http.get("http://127.0.0.1/vue.js/项目练习/api/json/goodsList.json").then(result =>{
                this.goodsList = result.body.message;
            })
        },
        getMore(){
            this.pageIndex++;
            this.getGoodsList();
        }
    }
}
</script>
<style lang="less" scoped>
    .goods-list{
        padding: 0 7px;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        .goods-item{
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            padding: 0 2px;
            margin: 4px 0px;
            width: 49%;
            border: 1px #ccc solid;
            box-shadow: -1px -1px 5px #888888;
            img{
                width: 100%;
            }
            .title{
                font-size: 14px;
            }
            .info{
                background-color: #eee;
                p{
                    margin: 0px;
                    padding: 5px;
                }
                .price{
                    .now{
                        color:red;
                        font-weight: bold;
                        font-size: 16px;
                    }
                    .old{
                        text-decoration: line-through;
                        font-size: 12px;
                        margin-left: 10px;
                    }
                }
                .sell{
                    display: flex;
                    justify-content: space-between;
                }
            }
        }
    }
</style> 